<?php 

$sql = "SELECT `Total Population`, `Male`, `Female`, `Males Over 18`, `Females Over 18`, `Males Over 65`, `Female Over 65` FROM `ZipCode Profile1` WHERE `ZCTA5` = $zipcode";

$result = mysql_query($sql,$db);
$num_rows = mysql_num_rows($result);
if ($result)
{
	$result_row = mysql_fetch_array($result,MYSQL_ASSOC);
	if($result_row)
	{
		$total_pop = $result_row['Total Population'];
		$male_pop = $result_row['Male'];
		$female_pop = $result_row['Female'];
		$male_over_18 = $result_row['Males Over 18'];
		$female_over_18 = $result_row['Females Over 18'];
		$male_over_65 = $result_row['Males Over 65'];
		$female_over_65 = $result_row['Female Over 65'];

	}
}

if($total_pop != 0)
{
$male_percet = number_format((100*$male_pop)/$total_pop,2);

$female_percet = number_format((100*$female_pop)/$total_pop,2);

$male_over_18_percet = number_format((100*$male_over_18)/$total_pop,2);

$female_over_18_percet = number_format((100*$female_over_18)/$total_pop,2);

$male_over_65_percet = number_format((100*$male_over_65)/$total_pop,2);

$female_over_65_percet = number_format((100*$female_over_65)/$total_pop,2);

echo "<Table width=250px cellspacing='-1' bordar=0>";
      echo "<tr style='width:100%; background:#F5DEB3; font-size:12px'>";
	  echo "<td >Total Population: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$total_pop;
	  echo "</td>";

	  echo "</tr>";
	  echo "<tr style='width:100%;font-size:12px'>";
	  echo "<td>Male Population: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$male_pop." (".$male_percet."%)";
	  echo "</td>";
	  echo "</tr>";
	  echo "<tr style='width:100%; background:#F5DEB3; font-size:12px'>";
	  echo "<td>Female Population: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$female_pop." (".$female_percet."%)";
	  echo "</td>";
	  echo "</tr>";
	  
	  echo "<tr style='width:100%;font-size:12px'>";
	  echo "<td>Males Over 18: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$male_over_18." (".$male_over_18_percet."%)";
	  echo "</td>";
	  echo "</tr>";
	  echo "<tr style='width:100%; background:#F5DEB3; font-size:12px'>";
	  echo "<td>Females Over 18: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$female_over_18." (".$female_over_18_percet."%)";
	  echo "</td>";
	  echo "</tr>";

	  echo "<tr style='width:100%;font-size:12px'>";
	  echo "<td>Males Over 65: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$male_over_65." (".$male_over_65_percet."%)";
	  echo "</td>";
	  echo "</tr>";
	  echo "<tr style='width:100%; background:#F5DEB3; font-size:12px'>";
	  echo "<td>Females Over 65: ";
	  echo "</td>";
	  echo "<td align='right' nowrap='nowrap'>".$female_over_65." (".$female_over_65_percet."%)";
	  echo "</td>";
	  echo "</tr>";

	  echo "</Table>";

}
else
{
$nodata_msg = "Data is not available.  Please make sure the City, State and Zipcode Information is correct.";

echo "<Table width=250px cellspacing='-1' bordar=0>";
      echo "<tr style='width:100%; background:#F5DEB3; font-size:12px'>";
	  echo "<td align='right' nowrap='nowrap'>".$nodata_msg;
	  echo "</td>";

	  echo "</Table>";


}


?>